package com.woniu.micropropertyserver.service.impl;


import com.alibaba.druid.sql.visitor.functions.Now;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.woniu.microcommonsserver.entity.DeployTenement;
import com.woniu.microcommonsserver.entity.TenementFaceCheck;
import com.woniu.micropropertyserver.mapper.TenementFaceMapper;
import com.woniu.micropropertyserver.service.ITenementFaceService;
import com.woniu.micropropertyserver.util.PageRest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class TenementFaceServiceImpl  implements ITenementFaceService {

    @Resource
    private TenementFaceMapper tenementFaceMapper;

    @Override
    public List<DeployTenement> findAll() {
        return tenementFaceMapper.findAll();
    }

    @Override
    public PageInfo findByParams(PageRest pageRest, DeployTenement deployTenement) {

            return PageHelper.startPage(pageRest.getPageNum(),pageRest.getPageSize()).doSelectPageInfo(()->tenementFaceMapper.findByParams(pageRest,deployTenement));
    }

    @Transactional(isolation = Isolation.DEFAULT,rollbackFor = Exception.class)
    @Override
    public int delInfo(Long[] ids) {
         for(Long id :ids){
             System.out.println(id);
         }
        return tenementFaceMapper.delInfo(ids);
    }

    @Transactional(isolation = Isolation.DEFAULT,rollbackFor = Exception.class)
    @Override
    public int updateAuth(Long[] ids, Date authorizeStartDate,Date authorizeEndDate) {
        System.out.println("开始时间："+authorizeStartDate);
        TenementFaceCheck tenementFaceCheck=new TenementFaceCheck();
        tenementFaceCheck.setAuthorizeEndDate(authorizeEndDate);
        tenementFaceCheck.setAuthorizeStartDate(authorizeStartDate);
        System.out.println(tenementFaceCheck);
        Date now= new Date();
    return  tenementFaceMapper.updateAuth(ids,tenementFaceCheck,now);
    }

    @Transactional(isolation = Isolation.DEFAULT,rollbackFor = Exception.class)
    @Override
    public int saveInfo(TenementFaceCheck tenementFaceCheck) {
        return tenementFaceMapper.saveInfo(tenementFaceCheck);
    }
}
